package com.hdy.common;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.view.View;

/**
 * 注册10下点击进入设置app的功能
 */
public class GoToSettings {

    public View mView;
    public final int MaxCount = 9;
    public int mCurrentCount = 0;

    public GoToSettings(View view) {
        mView = view;

    }

    public void tenClickEnter() {
        mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCurrentCount == MaxCount) {
                    goTOSettings(v.getContext());
                    mCurrentCount = 0;
                } else {
                    mCurrentCount++;
                }
            }
        });
    }

    public void longClickEnter() {
        mView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                goTOSettings(v.getContext());
                return true;
            }
        });
    }

    private void goTOSettings(Context context) {
        Intent intent = new Intent(Settings.ACTION_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}
